﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SuperJ.CMS.Interfaces.Repositories
{

    public interface ICMSRepository<T> where T : class
    {   
        /// <summary>
        /// 提取延迟加载数据
        /// </summary>
        /// <returns></returns>
        IQueryable<T> Fetch();
        /// <summary>
        /// 取所有数据，（直接加载到内存）
        /// </summary>
        /// <returns></returns>
        IEnumerable<T> GetAll();
        IEnumerable<T> Find(Func<T, bool> predicate);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        IEnumerable<T> Where(Func<T, bool> predicate);
        
        T Single(Func<T, bool> predicate);
        T SingleOrDefault(Func<T, bool> predicate);
        T First(Func<T, bool> predicate);
        void Create(T entity);
        void Delete(T entity);
        void Delete(Func<T, bool> predicate);
        void Attach(T entity);
        IQueryable<T> PageQuery(string propertyName, bool desc, int page, int pageSize);
        IQueryable<T> PageQuery(string propertyName, int page, int pageSize);
        IQueryable<T> OrderBy(string propertyName);
        IQueryable<T> OrderBy(string propertyName, bool desc);
        int Count();
        void SaveChanges();
    }
}
